package com.by.entity;

import com.by.common.group.ISave;
import com.by.common.group.IUpdate;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import org.springframework.validation.annotation.Validated;

import javax.validation.constraints.*;

//swagger中用于自定义类描述

@ApiModel(value = "用户")

public class User {
    //错误描述
    @Min(value = 1,message = "修改时id不能为空",groups = {IUpdate.class})
    //属性描述
    @ApiModelProperty(name = "id",value = "用户id",hidden = true,required = false)
    private int id;

    @NotBlank(message = "用户名不能为空!")
    @Length(min = 2,message = "用户名最少为2位!",groups = {ISave.class,IUpdate.class})//保存修改都生效
    @ApiModelProperty(value = "用户名",required = true)
    private String account;



    //    @NotBlank(message = "密码不能为空")
    @NotNull(message = "密码不能为空",groups = {ISave.class,IUpdate.class})
    @Pattern(regexp = "^[a-zA-Z0-9_]{6,12}$",message = "密码由字母,数字,下划线组成的6-12位",groups = {ISave.class,IUpdate.class})
    @ApiModelProperty(name = "passWord",value = "用户密码",required = true)
    private String password;
    /*
    * 身份
    *
    * */
    //隐藏
    @ApiModelProperty(value = "用户类型 1 公司员工 2 供应商 3 货代", hidden = true)
    private int type;
    private int status;
    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }
    @Min(value = 1, message = "修改时id不能为空", groups = {IUpdate.class})
    public int getId() {
        return id;
    }

    public void setId(@Min(value = 1, message = "修改时id不能为空", groups = {IUpdate.class}) int id) {
        this.id = id;
    }

    public @NotBlank(message = "用户名不能为空!") @Length(min = 2, message = "用户名最少为2位!", groups = {ISave.class, IUpdate.class}) String getAccount() {
        return account;
    }

    public void setAccount(@NotBlank(message = "用户名不能为空!") @Length(min = 2, message = "用户名最少为2位!", groups = {ISave.class, IUpdate.class}) String account) {
        this.account = account;
    }

    public @NotNull(message = "密码不能为空", groups = {ISave.class, IUpdate.class}) @Pattern(regexp = "^[a-zA-Z0-9_]{6,12}$", message = "密码由字母,数字,下划线组成的6-12位", groups = {ISave.class, IUpdate.class}) String getPassword() {
        return password;
    }

    public void setPassword(@NotNull(message = "密码不能为空", groups = {ISave.class, IUpdate.class}) @Pattern(regexp = "^[a-zA-Z0-9_]{6,12}$", message = "密码由字母,数字,下划线组成的6-12位", groups = {ISave.class, IUpdate.class}) String password) {
        this.password = password;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        if(type==0){
            this.type=1;
            return;
        }
        this.type = type;
    }
}
